package net.melon.sysres.inst.struts2;

import java.util.List;

import javax.inject.Inject;

import net.esj.basic.utils.StringUtils;
import net.esj.basic.utils.view.BaseJsonMessage.MessageLevel;
import net.esj.basic.view.AbstractPluginPageAction;
import net.melon.sysres.manager.SystemManager;
import net.melon.sysres.pojo.SysApplication;
import net.melon.sysres.pojo.SysFieldProperty;

public class FieldPropertyAction extends AbstractPluginPageAction<SysFieldProperty, SysFieldProperty> {

	private SystemManager systemManager;
	
	private String u;
	
	@Override
	protected void doQueryPage() {
		if(StringUtils.hasText(id)){
			pagination.setRows(systemManager.listFieldProperty(id,u,getRequest().getParameterMap()));
		}
	}
	
	public void urls(){
		List<String> list = systemManager.listFieldPropertyUrl(id);
		writeJson(list);
	}
	
	@Override
	protected void doUpdate() throws Exception {
		systemManager.updateFieldProperty(entity);
	}

	public void refresh(){
		systemManager.reloadApplicationClasses();
		writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), getText(ACTION_SUCCESS), MessageLevel.INFO, "html");
	}
	
	public void clonep(){
		systemManager.cloneFieldProperty(id, u);
		writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), getText(ACTION_SUCCESS), MessageLevel.INFO, "html");
	}

	public void setEntity(SysFieldProperty entity){
		this.entity = entity;
	}
	
	public SysFieldProperty getEntity(){
		return this.entity;
	}

	@Inject
	public void setSystemManager(SystemManager systemManager) {
		this.systemManager = systemManager;
	}

	public List<SysApplication> getApplications(){
		return systemManager.applications();
	}

	public String getU() {
		return u;
	}


	public void setU(String u) {
		this.u = u;
	}
	
}
